package main

import (
	"album/internal/config"
	"album/internal/server"
	"album/internal/svc"
	"album/kafka"
	"album/kafka/consumer"
	"flag"
	"fmt"
	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/core/service"
	"github.com/zeromicro/go-zero/zrpc"
	"go.uber.org/zap"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
	"grpc-common/album/types/album"
)

var configFile = flag.String("f", "etc/config.yaml", "the config file")

func main() {
	flag.Parse()

	var c config.Config
	conf.MustLoad(*configFile, &c)
	ctx := svc.NewServiceContext(c)
	svc := server.NewCategoryServer(ctx)
	go ConsumerProcessClient(ctx)
	svc.InitBloom()
	//svc.BatchSaveEs()
	s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
		album.RegisterAlbumServer(grpcServer, svc)

		if c.Mode == service.DevMode || c.Mode == service.TestMode {
			reflection.Register(grpcServer)
		}
	})
	defer s.Stop()

	fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
	s.Start()
}
func ConsumerProcessClient(config2 *svc.ServiceContext) {
	client := kafka.InitKafkaClient()
	processConsumer := consumer.NewTrackConsumer(config2, client)
	err := processConsumer.Start()
	if err != nil {
		zap.L().Error("kafka chatConsumer 启动失败", zap.Error(err))
		return
	}
}
